package fr.unice.polytech.chord.gui.dialogs;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

import fr.unice.polytech.chord.gui.ChordVisualizer;

/**
 * Abstract dialogs used for dialogs associated to toolbar in
 * {@link ChordVisualizer} graphical user interface.
 * 
 * @author Anthony Parisy
 * @author Laurent Pellegrino
 * @author Marc Valdener
 * 
 * @version 06/11/2009
 */
@SuppressWarnings("serial")
public abstract class ToolBarJDialog extends JDialog {

	public ToolBarJDialog(JFrame parent, String title,
			final JButton toolBarButton) {
		super(parent, title);

		super.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				super.windowClosing(e);
				if (toolBarButton != null) {
					toolBarButton.setEnabled(true);
				}
			}
		});

		super.addComponentListener(new ComponentListener() {

			@Override
			public void componentShown(ComponentEvent e) {
			}

			@Override
			public void componentResized(ComponentEvent e) {
			}

			@Override
			public void componentMoved(ComponentEvent e) {
			}

			@Override
			public void componentHidden(ComponentEvent e) {
				if (toolBarButton != null) {
					toolBarButton.setEnabled(true);
				}
			}
		});
	}

}
